package serialize2;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;
import serialize2.PersonDetails;

public class GetPersonDetails {

	public static void main(String[] args) {
		PersonDetails pr = null;
		String filename = "person.txt";
		List pDetails = null;
		FileInputStream fis = null;
		ObjectInputStream in = null;

		try {
			fis = new FileInputStream(filename);
			in = new ObjectInputStream(fis);
			pDetails = (ArrayList) in.readObject();
			in.close();
		} catch (IOException ex) {
			ex.printStackTrace();
		} catch (ClassNotFoundException ex) {
			ex.printStackTrace();
		}
		// print out the size
		System.out.println("Person Details Size: " + pDetails.size());

		for (int i = 0; i < 3; i++) {
			pr = (PersonDetails) pDetails.get(i);
			System.out.println("Name " + pr.getName());
			System.out.println("Age " + pr.getAge());
			System.out.println("Sex " + pr.getSex());
			System.out.println();
		}
	}
}
